package com.nb.java14.BlackBerry.ui.widgets;

import net.rim.device.api.i18n.Locale;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.component.EditField;

/**
 * NOTA: Esta clase NO esta lista para usar.
 *
 * @author Nahuel Barrios.
 * @version 1.0
 * @since 20/07/2010.
 */
public class FixedWidthField extends EditField {

	/** private members of the FixedWidthField class */
	private Font defaultFont;
	/** used to get the default font */
	private String text;
	/** The maximum number of chars. We use this value to set the width. */
	private int maxNumChars;

	/**
	 * Used to specify the default width of the table cells constructor calls the super class constructor
	 *
	 * @param label
	 * @param initialValue
	 * @param maxNumChars
	 * @param style
	 */
	public FixedWidthField(String label, String initialValue, int maxNumChars,
						   long style) {
		super(label, initialValue, maxNumChars, style);
		this.maxNumChars = maxNumChars;
	}


	/** Sobreescribo el metodo que me dara la altura del Field en base a la constante que definimos en MainKeys.java14 */
	public int getPreferredHeight() {
		return 14;//  ToDo: Functionality: ver este size!!
	}


	/** Overrides the default getPreferredWidth functionality to return a fixed width */
	public int getPreferredWidth() {
		defaultFont = Font.getDefault();

		text = "";
		for (int i = 0; i < maxNumChars; i++)
			text += "0";

		return defaultFont.getAdvance(text);
	}

	/** Overrides the default layout functionality to set the width of the table cell */
	protected void layout(int width, int height) {
		width = getPreferredWidth();
		height = super.getPreferredHeight();

		// uses the super class' layout functionality after the width and the height are set
		super.layout(width, height);

		// uses the super class' setExtent functionality after the width and the height are set
		super.setExtent(width, height);

	}

	public int getTextInputStyle() {
		return 0; //  ToDo: Functionality:
	}

	public boolean isUnicodeInputAllowed() {
		return false;					  //  ToDo: Functionality:
	}

	public void updateInputStyle() {
		//  ToDo: Functionality:
	}

	public Locale getPreferredInputLocale() {
		//  ToDo: Functionality: 
		return null;
	}
}
